package com.github.niefy.modules.wx.manage;

import com.github.niefy.modules.wx.service.MassTextService;
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.List;
import java.util.Map;

//消息群发控制器
@RestController
@RequestMapping("/massSendMsg")
public class WxMassTextController{
    @Autowired
    MassTextService massTextService;


    /**
     * 根据openid群发消息
     * mediaId 媒体ID
     * openids Openid字符列表
     * type 消息类型(text,image,npnews,npvideo,voice)
     * @param param
     * @return
     */
    @GetMapping("/massSendByOpenid")
    public WxMpMassSendResult massSendByOpenid(@RequestParam Map<String,String> param) {
        String mediaId = param.get("mediaId");
        String[] openids = param.get("openids").split(",");
        String type = param.get("type");
        return massTextService.massSendByOpenid(mediaId,openids,type);
    }

    /**
     * 根据用户标签群发消息
     * mediaId 素材ID
     * tagId 标签ID
     * type 消息类型(text,image,npnews,npvideo,voice)
     * @param param
     * @return
     */
    @GetMapping("/massSendByTagId")
    public WxMpMassSendResult massSendByTagId(@RequestParam Map<String,Object> param) {
        String mediaId = param.get("mediaId").toString();
        Long tagId = Long.valueOf(param.get("tagId").toString());
        String type = param.get("type").toString();
        return massTextService.massSendByTagId(mediaId,tagId,type);
    }
}
